import { _decorator, EventMouse, Node } from "cc";
import { BaseTriggerManager } from "./base-trigger-manager";
import { BackPackManager } from "../back-pack-manager";
import { ItemType, TriggerStatus } from "../model";
import { DataManager } from "../runtime/data-manager";
const { ccclass, property } = _decorator;

@ccclass("MailTriggerManager")
export class MailTriggerManager extends BaseTriggerManager {
  @property(Node)
  openNode: Node = null;

  @property(Node)
  closeNode: Node = null;

  handlerTrigger(event: EventMouse) {
    if (BackPackManager.Instance.isItemInHand(ItemType.Key)) {
      BackPackManager.Instance.useItem(ItemType.Key);
    }
  }

  render() {
    const hasResolved =
      DataManager.Instance.mailBoxStatus === TriggerStatus.Resolved;
    this.openNode.active = hasResolved;
    this.closeNode.active = !hasResolved;
  }
}
